package dto

import (
	"tuowei.com/app/admin/models"
	"tuowei.com/common/dto"
	common "tuowei.com/common/models"
)

type SysExercisesWareInsertReq struct {
	Id               int    `json:"id"`
	QuestionBankId   int    `json:"question_bank_id" comment:"关联ID" vd:"$>0; msg:'关联ID不能为空'"`
	Name             string `json:"name" comment:"子章节名称" vd:"@:len($)>0; msg:'子章节名称不能为空'"`
	QuestionBankWare string `json:"question_bank_ware" comment:"子章节课件url地址"`
	Sort             int    `json:"sort" comment:"排序"`
	Pid              int    `json:"pid" comment:"父级ID"`
	IsShow           int    `json:"is_show" comment:"是否显示"`
	IsFree           int    `json:"is_free" comment:"是否付费公开范围"`
	common.ControlBy
}

type SysExercisesGetPageByLinkIdReq struct {
	LinkId int `json:"link_id" comment:"关联ID" vd:"$>0; msg:'关联ID不能为空'"`
}

func (m *SysExercisesGetPageByLinkIdReq) GetNeedSearch() interface{} {
	return *m
}

func (s *SysExercisesWareInsertReq) Generate(model *models.SysExercisesWare) {
	model.Name = s.Name
	model.Sort = s.Sort
	model.IsShow = 0
	model.QuestionBankWare = s.QuestionBankWare
	model.QuestionBankId = s.QuestionBankId
	model.IsFree = s.IsFree
	model.Pid = s.Pid
	if s.Pid == 0 {
		model.Level = 1
	} else {
		model.Level = 2
	}
	model.CreateBy = s.CreateBy
	model.Creator = s.Creator
}

func (s *SysExercisesWareInsertReq) GetId() interface{} {
	return s.Id
}

type SysExercisesWareGetTreeByCourseIdReq struct {
	QuestionBankId int `json:"question_bank_id" comment:"题库ID"`
}

type SysExercisesWareChangeReq struct {
	ExercisesWareId int    `json:"exercises_ware_id" comment:"练习题章节ID" vd:"$>0; msg:'练习题章节ID不能为空'"`
	Url             string `json:"url" comment:"课件url地址" vd:"@:len($)>0; msg:'课件链接地址不能为空'"`
	common.ControlBy
}

func (e SysExercisesWareChangeReq) Generate(model *models.SysCourseWare) {
	model.Id = e.ExercisesWareId
	model.CourseWare = e.Url
}

func (e SysExercisesWareChangeReq) GetId() int {
	return e.ExercisesWareId
}

type SysExercisesWareDeleteByIdReq struct {
	dto.ObjectById
	common.ControlBy
	LinkId int `json:"link_id"`
}

type SysExercisesWareDeleteLargeChapterByIdReq struct {
	dto.ObjectById
	common.ControlBy
}

func (s *SysExercisesWareDeleteLargeChapterByIdReq) GetId() interface{} {
	return s.Id
}

type SysExercisesWareUpdateReq struct {
	Id               int    `json:"id" vd:"$>0; msg:'课件ID不能为空'"`
	QuestionBankId   int    `json:"question_bank_id" comment:"关联ID" vd:"$>0; msg:'关联ID不能为空'"`
	Name             string `json:"name" comment:"子章节名称" vd:"@:len($)>0; msg:'子章节名称不能为空'"` // 子章节名称
	QuestionBankWare string `json:"question_bank_ware" comment:"课件地址"`                     // 课件地址
	Pid              int    `json:"pid"`
	Sort             int    `json:"sort"`
	IsShow           int    `json:"is_show" comment:"是否显示"`
	IsFree           int    `json:"is_free" comment:"是否付费公开范围"`
	common.ControlBy
}

func (s *SysExercisesWareUpdateReq) Generate(model *models.SysExercisesWare) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Name = s.Name
	model.IsShow = 0
	model.QuestionBankWare = s.QuestionBankWare
	model.QuestionBankId = s.QuestionBankId
	model.Pid = s.Pid
	model.Sort = s.Sort
	model.IsFree = s.IsFree
	if s.Pid == 0 {
		model.Level = 1
	} else {
		model.Level = 2
	}
	model.UpdateBy = s.UpdateBy
	model.Updater = s.Updater

}

func (s *SysExercisesWareUpdateReq) GetId() interface{} {
	return s.Id
}

type ExercisesWareTree struct {
	Id       int                 `gorm:"-" json:"id"`
	LinkId   int                 `json:"link_id" gorm:"-"`
	Type     string              `json:"type" gorm:"-"`
	Sort     int                 `json:"sort" gorm:"-"`
	Name     string              `gorm:"-" json:"name"`
	Url      string              `json:"url" gorm:"-"`
	Pid      int                 `json:"pid" gorm:"-"`
	Children []ExercisesWareTree `gorm:"-" json:"children"`
}
